package com.ccom.api.dto;

import com.ccom.core.common.util.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * @Description
 * @Author zjj
 * @Date 2021/10/26
 */
@Data
@ApiModel(value = "用户保存对象", description = "用户保存对象")
public class UserSaveDto {
    @ApiModelProperty(value = "用户名，登录账户", required = true)
    private String userName;

    @ApiModelProperty(value = "密码，加密存储")
    private String password;

    @ApiModelProperty(value = "注册手机号")
    private String phone;

    @ApiModelProperty(value = "注册邮箱")
    private String email;

    @ApiModelProperty(value = "会员来源：1:PC，2：H5，3：Android，4：IOS, 5：其他")
    private String sourceType;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "真实姓名")
    private String name;

    @ApiModelProperty(value = "头像地址")
    private String headPic;

    @ApiModelProperty(value = "QQ号码")
    private String qq;

    @ApiModelProperty(value = "性别，1男，0女")
    private String sex;

    @ApiModelProperty(value = "出生年月日")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birthday;

    /**
     * 检查用户名是否符合规范
     *
     * @return: boolean true:规范  false:不规范
     **/
    public boolean checkUserName(){
        return !(StringUtils.isEmpty(this.getUserName()) && StringUtils.isEmpty(this.getPhone()) && StringUtils.isEmpty(this.getEmail()));
    }

    /**
     * 检查用户名是否符合规范,并设置用户名
     *
     * @return: boolean true:规范  false:不规范
     **/
    public boolean checkAndSetUserName(){
        if (checkUserName()){
            if (StringUtils.isEmpty(this.getUserName())){
                this.userName=StringUtils.isNotEmpty(this.phone)?this.phone:this.email;
            }
            return true;
        }
        return false;
    }

}
